# 冒泡排序# 定义列表 list      横向输出
arays = [1,8,2,6,3,9,4]
for i in range(len(arays)):
    for j in range(i+1):
        if arays[i] < arays[j]:
            # 实现连个变量的互换
            arays[i],arays[j] = arays[j],arays[i]
print (arays)



#冒泡排序            纵向输出
array = [9,2,7,4,5,6,3,8,1,10]
L = len(array)
for i in range(L):
    for j in range(L-i):
        if array[L-j-1]<array[L-j-2]:
            array[L-j-1],array[L-j-2]=array[L-j-2],array[L-j-1]
for i in range(L):
    print (array[i],)

#冒泡排序
def bubbleSort(arr):
    l = len(arr)
    for i in range(l):
        flag = False
        for j in range(l-i-1):
            if arr[j] > arr[j+1]:
                arr[j],arr[j+1] = arr[j+1],arr[j]
                flag = True
        if flag == False:
            break
    return arr
    
print(bubbleSort([5,5,5,2,3,8,1]))
